//**********************************************************
//    File Name: Appointment.cs
//    Author: Team Motif
//    Date Created : 04/13/2007
//    Current Owner: Team Motif 
//                                                                            
//    Purpose: 
//    Appointment Class with all the methods to get and set Client,
//    HCW, StartTime, EndTime
//	  Copyright 2007
//**********************************************************
using System;
using System.Collections;
using System.Text;
using System.Data.SqlClient;


namespace Library
{
    public class Appointment  
    {
        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Constructor for Appointment class.  
        /// -------------------------------------------------------------------------------
        /// </summary>
        public Appointment()
        {
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Constructor for Appointment class.  Accepts a client, worker, and time range for 
        /// the appointment.
        /// -------------------------------------------------------------------------------
        /// </summary>
        public Appointment(Client client, HomeCareWorker worker, DateTime start, DateTime end)
        {
            mClient = client;
            mWorker = worker;
            mStartTime = start;
            mEndTime = end;
        
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns a list of 1 or more appointments given a startViewDate.
        /// -------------------------------------------------------------------------------
        /// </summary>
        public static ArrayList GetAppointmentByDate(DateTime startViewDate)
        {
            ArrayList apptList = new ArrayList();

            System.Object lockThis = new System.Object();
            lock (lockThis)
            {                
                apptList = DBUtil.ReadApptList(startViewDate);
            }
            return apptList;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns a list of 1 or more appointments for a Client given a date range.
        /// -------------------------------------------------------------------------------
        /// </summary>
        public static ArrayList GetAppointmentByClient(Client client, DateTime start, DateTime end)
        {
            ArrayList apptList = new ArrayList();

            System.Object lockThis = new System.Object();
            lock (lockThis)
            {
                apptList = DBUtil.ReadClientApptList(client, start, end);
            }
            return apptList;
        }


        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Write an appoinment to the Database
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <param name="appt"></param>
        public static bool SaveAppointment(long clientID, long hcwID, DateTime start, DateTime end)
        {
            System.Object lockThis = new System.Object();
            lock (lockThis)
            {
                if (DBUtil.SaveCreatedAppointment(clientID, hcwID, start, end) == false)
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the client for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        public Client GetClient()
        {
            return mClient;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the client FName + LName 
        /// -------------------------------------------------------------------------------
        /// </summary>
        public String GetClientName(Client client)
        {
            String clientName = client.GetFirstName() + " " + client.GetLastName();
            return clientName;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Sets the client for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        public void SetClient(Client client)
        {
            this.mClient = client;
        }


        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the home care worker for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        public HomeCareWorker GetHomeCareWorker()
        {
            return mWorker;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the HCWName FName LName for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        public String GetHcwName(HomeCareWorker worker)
        {
            String workerName = worker.GetFirstName() + " " + worker.GetLastName();
            return workerName;
        }
            
        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Set the home care worker for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <param name="hcw"></param>
        public void SetHomeCareWorker(HomeCareWorker hcw)
        {
            this.mWorker = hcw;
        }

       /// <summary>
        /// -------------------------------------------------------------------------------
       /// Returns the begin date time for this appointment
        /// -------------------------------------------------------------------------------
       /// </summary>
       /// <returns></returns>
        public DateTime GetBeginDateTime()
        {
            return mStartTime;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the begin time for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <returns></returns>
        public int GetBeginTime()
        {
            return mStartTime.Hour;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Sets the begin date time for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <param name="date"></param>
        public void SetBeginDateTime(DateTime date)
        {
            mStartTime = date;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the end date time for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <returns></returns>
        public DateTime GetEndDateTime()
        {
            return mEndTime;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Returns the end time for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <returns></returns>
        public int GetEndTime()
        {
            return mEndTime.Hour;
        }

        /// <summary>
        /// -------------------------------------------------------------------------------
        /// Sets the end date time for this appointment
        /// -------------------------------------------------------------------------------
        /// </summary>
        /// <param name="date"></param>
        public void SetEndDateTime(DateTime date)
        {
            mEndTime = date;
        }

        // -------------------------------------------------------------------------------
        // Private data region
        // -------------------------------------------------------------------------------
        Client mClient;
        HomeCareWorker mWorker;
        DateTime mStartTime;
        DateTime mEndTime;
        static Utility DBUtil = new Utility();
        
    }
}
